﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace XAPI.Data.Configuration
{
    public class VerbConfigurationSection : ConfigurationSection
    {
        [ConfigurationProperty("verbs")]
        [ConfigurationCollection(typeof(VerbElement), AddItemName = "verb", ClearItemsName = "clear", RemoveItemName = "remove")]
        public GenericConfigurationElementCollection<VerbElement> Verbs
        {
            get
            {
                return (GenericConfigurationElementCollection<VerbElement>)this["verbs"];
            }
            set
            { this["verbs"] = value; }
        }
    }

    public class VerbElement : ConfigurationElement
    {
        // Create an "id" element.
        [ConfigurationProperty("id")]
        public string Id
        {
            get
            {
                return (string)this["id"];
            }
            set
            { this["id"] = value; }
        }

        [ConfigurationProperty("display")]
        [ConfigurationCollection(typeof(MapElement), AddItemName = "map", ClearItemsName = "clear", RemoveItemName = "remove")]
        public GenericConfigurationElementCollection<MapElement> Maps
        {
            get
            {
                return (GenericConfigurationElementCollection<MapElement>)this["display"];
            }
            set
            { this["display"] = value; }
        }
    }

    // Define the "display" element
    // with "language" and "value" attributes.
    public class MapElement : ConfigurationElement
    {
        [ConfigurationProperty("language", IsRequired = true)]
        // TODO: string validation is throwing an exception
        //[StringValidator(InvalidCharacters = "<>", MinLength = 1, MaxLength = 60)]
        public string Language
        {
            get
            {
                return (string)this["language"];
            }
            set
            {
                this["language"] = value;
            }
        }

        [ConfigurationProperty("value", IsRequired = true)]
        public string Value
        {
            get
            { return (string)this["value"]; }
            set
            { this["value"] = value; }
        }
    }
}